import axios from 'axios';
import {getCredentials} from "@/main/lcu/LcuCertificate.js";
import https from "https";

const httpClient = axios.create({
    timeout: 10000,
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
    },
    agent: new https.Agent({                 // 创建自定义Agent
        rejectUnauthorized: false              // 忽略证书错误
    }),
});

httpClient.interceptors.request.use((config) => {
    let url = config.url;
    url = url.startsWith("/") ? url.substring(1) : url;
    const {token, port} = getCredentials();
    //代理服务只处理图片请求  常规服务使用原服务器地址
    config.url = `https://127.0.0.1:${port}/${url}`
    config.headers['Authorization'] = token;
    return config;
})

export {
    httpClient
}

